package pe.com.bbva.ge.vista.vaadin.ui.utileria;

import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.util.Set;

import javax.validation.Validation;
import javax.validation.ValidatorFactory;

import pe.com.bbva.ge.utileria.UtileriaComun;
import pe.com.bbva.ge.vista.vaadin.ui.utileria.bean.BeanValidar;
import pe.com.bbva.ge.vista.vaadin.ui.utileria.exception.ValidacionException;

import com.vaadin.data.Validator;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;

public abstract class UtileriaVista {

	private UtileriaVista() {}
	
	public static final BigDecimal obtenerBigDecimal(TextField txt)
	{
		return UtileriaComun.obtenerBigDecimal((String)txt.getValue());
	}
	
	public static void validar (Window window, Object object){
		/*ValidatorFactory factory=Validation.buildDefaultValidatorFactory();
		Validator validator = factory.getValidator();
		Field[] allFields = object.getClass().getDeclaredFields();
	    for (Field field : allFields) {
	        if (Modifier.isPrivate(field.getModifiers())) {
	            Set<ConstraintViolation<Object>> constraintViolations = validator.validateProperty(object, field.getName());
	            for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
	            	throw new ValidacionException(constraintViolation.getMessage(),
	            			new Object[]{constraintViolation.getPropertyPath()});
	    		}
	        }
	    }*/
	}
	
	public static void validar (Window window, Object object, BeanValidar[] listValidar){
		/*ValidatorFactory factory=Validation.buildDefaultValidatorFactory();
		Validator validator = factory.getValidator();
	    for (BeanValidar validar : listValidar) {
            Set<ConstraintViolation<Object>> constraintViolations = validator.validateProperty(object, validar.getPropiedad());
            for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
            	if(validar.getObjecto()!=null){
            		validar.getObjecto().focus();
            	}
            	throw new ValidacionException(constraintViolation.getMessage(),validar.getArgs());
    		}
	    }*/
	}
	
}
